<template>
  <div class="base-collapse">
    <div class="header"> 对接信息录入 </div>
    <div class="base-collapse-content">
      <BasicForm @register="registerForm" />
      <div style="width: 100%; text-align: right">
        <a-button style="margin-right: 16px" @click="handleRest">重置</a-button>
        <a-button type="primary" @click="handleSubmit">保存</a-button>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
  import { defineComponent, onMounted } from 'vue';
  import { useForm, BasicForm } from '/@/components/Form';
  import { zhuyunFormSchema } from './Zhuyun.data';
  import { getThirdConfigByTenantId, saveOrUpdateThirdConfig } from './ThirdApp.api';
  import { getTenantId } from '@/utils/auth';

  export default defineComponent({
    name: 'ThirdAppWeEnterpriseConfigForm',
    components: { BasicForm },
    setup() {
      //表单配置
      const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
        schemas: zhuyunFormSchema,
        showActionButtonGroup: false,
        labelWidth: 150,
        wrapperCol: { span: 16 },
        baseColProps: { span: 12 },
      });
      /**
       * 初始化数据
       *
       * @param params
       */
      async function initThirdAppConfigData(params) {
        await resetFields();
        let values = await getThirdConfigByTenantId(params);
        if (values) {
          await setFieldsValue(values);
        }
      }

      onMounted(() => {
        let tenantId = getTenantId();
        initThirdAppConfigData({ tenantId: tenantId, thirdType: 'zhuyun' });
      });
      function handleRest() {
        let tenantId = getTenantId();
        initThirdAppConfigData({ tenantId: tenantId, thirdType: 'zhuyun' });
      }
      async function handleSubmit() {
        let values = await validate();
        console.log(values, 56);

        let isUpdate = false;
        if (values.id) {
          isUpdate = true;
        }
        await saveOrUpdateThirdConfig(values, isUpdate);
      }

      return {
        registerForm,
        handleSubmit,
        handleRest,
      };
    },
  });
</script>

<style lang="less" scoped>
  .header {
    align-items: center;
    box-sizing: border-box;
    display: flex;
    height: 50px;
    justify-content: space-between;
    font-weight: 700;
    font-size: 18px;
    color: @text-color;
  }

  .flex-flow {
    display: flex;
    min-height: 0;
  }

  .sync-padding {
    padding: 12px 0 16px;
    color: @text-color;
  }

  .base-collapse {
    // margin-top: 20px;
    padding: 20px 24px;
    font-size: 20px;
    display: flex; 
    flex-direction: column;
    overflow: auto;
    .base-desc {
      font-size: 14px;
      color: @text-color;
    }

    .base-title {
      width: 140px;
      text-align: right;
      height: 50px;
      line-height: 50px;
      margin-right: 15px;
    }

    .base-message {
      width: 100%;
      height: 50px;
      line-height: 50px;
    }

    :deep(.ant-collapse-header) {
      padding: 12px 0 16px;
    }

    :deep(.ant-collapse-content-box) {
      padding-left: 0;
    }
  }
  .base-collapse-content {
    display: flex; 
    flex-direction: column; 
    justify-content: space-between;
    flex: 1;
  }
  /*begin 兼容暗夜模式*/
  //暗黑模式下卡片的边框设置成none
  [data-theme='dark'] .base-collapse .ant-collapse {
    border: none !important;
  }
  /*end 兼容暗夜模式*/
  /*文档按钮问号样式*/
  .sync-text {
    margin-left: 2px;
    cursor: pointer;
    position: relative;
    top: 2px;
  }
</style>
